//
//  YFTopicSynShareCell.m
//  PhotoManager
//
//  Created by Coollang on 2017/9/5.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "YFTopicSynShareCell.h"
#import "JCGetLocation.h"
#import "JCLocation.h"
#import "NSAttributedString+RichText.h"

@interface YFTopicSynShareCell ()
@property (weak, nonatomic) IBOutlet UILabel *synLabel;
@property (weak, nonatomic) IBOutlet UIButton *qzoneButton;
@property (weak, nonatomic) IBOutlet UIButton *weChatButton;
@property (weak, nonatomic) IBOutlet UIButton *momentsButton;
@property (weak, nonatomic) IBOutlet UIButton *qqButton;
@property (weak, nonatomic) IBOutlet UILabel *locationDescLabel;
@property (weak, nonatomic) IBOutlet UIView *locationView;
@property (weak, nonatomic) IBOutlet UITextField *telephoneInput;

// 当前选中的Button
@property (nonatomic, strong) UIButton *currnetBtn;

@end

@implementation YFTopicSynShareCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = kSeparationLineColor;
    
    self.synLabel.text = NSLocalizedString(@"Sync to", @"同步到");
    [self.telephoneInput drawLineWithStartPoint:CGPointMake(0, 43) endPoint:CGPointMake(kYFScreenWidth - 20, 43) lineColor:[UIColor colorWithWhite:1.0 alpha:0.2] lineWidth:1];
    self.telephoneInput.attributedPlaceholder = [NSAttributedString attributedString:@"E-mail Address" subString:@[@"E-mail Address"] colors:@[kTLightGray999]];
}

- (void)setType:(PostTopicType)type{
    _type = type;
    if (type == PostTopicTypeFeedBack) {
        _locationView.hidden = YES;
        _telephoneInput.hidden = NO;
    }else if (type == PostTopicTypeMoment){
        _locationView.hidden = NO;
        _telephoneInput.hidden = YES;
        
        __weak typeof(self)weakSelf = self;
        if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)) {
            //定位功能可用
            [JCGetLocation locationComplete:^(NSString *result) {
                weakSelf.locationDescLabel.text = result;
            }];
        }else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {
            //定位不能用
            _locationDescLabel.minimumScaleFactor = 0.5;
            
            _locationDescLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Please Allow %@ to access your album in \"Settings -> Privacy -> Location\"", nil),[NSString appCurrentName]];
            return;
        }
    }
}

- (NSString *)phoneNumber{
    return _telephoneInput.text;
}

- (IBAction)locationBtnClick:(UIButton *)sender {
}

- (IBAction)btnClickAction:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    
//    SSDKPlatformType type = SSDKPlatformTypeUnknown;
    
    if (self.currnetBtn == sender) {
        self.currnetBtn = nil;
    }else {
        self.currnetBtn.selected = NO;
        self.currnetBtn = sender;
//        switch (self.currnetBtn.tag) {
//            case 31:
//                type = SSDKPlatformTypeWechat;
//                break;
//            case 32:// 朋友圈
//                type = SSDKPlatformSubTypeWechatTimeline;
//                break;
//            case 33:
//                 type = SSDKPlatformSubTypeQQFriend;
//                break;
//            case 34:
//                type = SSDKPlatformSubTypeQZone;
//                break;
//        }
    }
    
//    if (self.SynButtonClickBlock) {
//        self.SynButtonClickBlock(type);
//    }
}

@end
